/*
This file runs the analyses that make up the  results for the child penalty exercises
The following tables and figures are created in this do file:
Table 5
Table 6
Figure 2
FIGURE A.II
Figure A.I
Table 2 
Table A. IV
*/


**** ORIGINAL PRIMARY RESULTS
use "U:\dtafiles\penaltysample_v1.dta", clear
 *** If you run county vs non-county And the run distances separately, there are different singletons that get dropped. Create indicator based on being in distance groups
 g insample_nocontrol = 0
 foreach num of numlist 1 2 3 4{
 	  reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1& (mother_miss != 1 |father_miss != 1) & headspouse == 1 & dist_cat == `num', absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 replace  insample_nocontrol = 1 if e(sample)
 }
 
 
 **** TABLE 5, Panel B
 eststo clear 
 eststo: reghdfe inc_f_adj pre_period_omit2 eventpre1 event0 ///
 postperiod college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & grandparent_birth == 1 & insample_nocontrol == 1 , absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 
  eststo: reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & headspouse == 1 & insample_nocontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff County
 
   eststo: reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1& (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & dist_birth > 25 & headspouse == 1 & insample_nocontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff County & > 25 miles
 
   eststo: reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1& (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & headspouse == 1 & insample_nocontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff State
 
   eststo: reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1& (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & dist_birth > 25 & headspouse == 1 & insample_nocontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff State & > 25 miles
 
 foreach num of numlist 1 2 3 4{
 	 eststo: reghdfe inc_f_adj pre_period_omit2  eventpre1 event0 ///
 postperiod  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1& (mother_miss != 1 |father_miss != 1) & headspouse == 1 & dist_cat == `num' & insample_nocontrol == 1, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 
 }
 
  
 esttab using "aggregated_penalty_coef_nocontrol_05242024.csv", se replace keep(postperiod )
 eststo clear
 *** Getting Mean Baseline values for each regression
estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==1, d
eststo  col1
estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0, d
eststo col2
estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & dist_birth > 25, d
eststo col3
estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1, d
eststo col4
estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & dist_birth > 25, d
eststo col5 
foreach num of numlist 1 2 3 4{
	estpost summ inc_f_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & dist_cat ==`num', d
	eststo cola`num'
}

esttab col1 col2 col3 col4 col5 col1 cola1 cola2 cola3 cola4 using "U:\output\aggregated_penalty_mean_nocontrol_02212024.csv", main(mean) replace

 ***** TABLE 5 PANEL A
 // Now with male control group
  g insample_malecontrol = 0
 foreach num of numlist 1 2 3 4{
 	   reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black  miss* [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & dist_cat == `num', absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 replace  insample_malecontrol = 1 if e(sample)
 }
  eststo clear 
 eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black miss* [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & grandparent_birth == 1 & insample_malecontrol == 1, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 
  eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod) college hsdegree white black  miss*  [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)& grandparent_birth ==0 & headspouse == 1& insample_malecontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff County
 
   eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black  miss* [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)& grandparent_birth ==0 & dist_birth > 25 & headspouse == 1& insample_malecontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff County & > 25 miles
 
   eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black miss*  [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)& nograndparent_birth ==1 & headspouse == 1& insample_malecontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff State
 
   eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black miss*  [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)& nograndparent_birth ==1 & dist_birth > 25 & headspouse == 1& insample_malecontrol == 1, absorb(age_f year resp_statecounty  ) vce(cluster uniqid) // All, Diff State & > 25 miles
 
 foreach num of numlist 1 2 3 4{
 	 eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black  miss* [pw=grandparent_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & dist_cat == `num'& insample_malecontrol == 1, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, same County
 
 }
 
 esttab using "aggregated_penalty_coef_malecontrol_05242024.csv", se replace keep( 2.sex_ind#1.postperiod)
 
 
**** means for panel A
 estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==1, d
eststo  col1
estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0, d
eststo col2
estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & dist_birth > 25, d
eststo col3
estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1, d
eststo col4
estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & dist_birth > 25, d
eststo col5 
foreach num of numlist 1 2 3 4{
	estpost summ inc_adj  [w=grandparent_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & dist_cat ==`num', d
	eststo cola`num'
}

esttab col1 col2 col3 col4 col5 cola1 cola2 cola3 cola4 using "U:\output\aggregated_penalty_mean_malecontrol_02212024.csv", main(mean) replace
 
 
 
**** TABLE 6 Aggregated Child Penalty, by Childcare Costs 
 // Child Care Costs
 

  eststo clear 
 eststo: reghdfe inc_f_adj c.CC_in10s##(pre_period_omit2 eventpre1 event0 ///
 postperiod)  college hsdegree white black  miss* [pw=cc_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 , absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All Interacted with Weekly CC Cost
 mat list e(b)
  eststo: reghdfe inc_f_adj (pre_period_omit2 eventpre1 event0 ///
 postperiod)  college hsdegree white black  miss* [pw=cc_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & above75CC == 1, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, High Costs
   eststo: reghdfe inc_f_adj (pre_period_omit2 eventpre1 event0 ///
 postperiod)  college hsdegree white black  miss*  [pw=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper == 1 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & above75CC == 0, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, Low Costs
     
 eststo: reghdfe inc_adj sex_ind##(c.CC_in10s##(pre_period_omit2 eventpre1 event0 ///
 postperiod))   college hsdegree white black  miss* [pw=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & headspouse == 1 , absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All Interacted with Weekly CC Cost
 mat list e(b)
  eststo: reghdfe inc_adj sex_ind##(pre_period_omit2 eventpre1 event0 ///
 postperiod)  miss*  [pw=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & above75CC == 1, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, High Costs
   eststo: reghdfe inc_adj sex_ind##(pre_period_omit2  eventpre1 event0 postperiod)  college hsdegree white black  miss*  [pw=cc_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & headspouse == 1 & above75CC == 0, absorb(age_f year  resp_statecounty) vce(cluster uniqid) // All, Low Costs
   
 esttab est2 est3 est1 est5 est6 est4 using "aggregated_penalty_coef_childcare_02212024.csv", se replace keep( postperiod 1.postperiod 1.postperiod#c.CC_in10s 2.sex_ind#1.postperiod 2.sex_ind#1.postperiod#c.CC_in10s )
  *** Getting Mean Baseline values for each regression
eststo clear
estpost summ inc_f_adj [w=cc_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & above75CC ==1, d // high CCCC
eststo col1
estpost summ inc_f_adj  [w=cc_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & above75CC ==0, d // low CCC
eststo col2 
estpost summ inc_f_adj [w=cc_weight]  if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) , d // everyone
eststo col3 

estpost summ inc_adj  [w=cc_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & above75CC ==1, d // high CCC, male control
eststo col4
estpost summ inc_adj  [w=cc_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & above75CC ==0, d
eststo col5  // low CCC, male control
estpost summ inc_adj  [w=cc_weight] if  eventpre_orig ==1 & insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) , d // all, male control
eststo col6
esttab col1 col2 col3 col4 col5 col6 using "U:\output\aggregated_penalty_mean_childcare_02212024.csv", main(mean) replace


/* This code outputs frequencies in cells for each regression to meet disclosure guidelines for PSID


*** To output  frequencies
 foreach var of varlist eventpost* event0 eventpre*{
 	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . 
   tab `var'  if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & dist_cat <=2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != .
tab `var'  if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & grandparent_birth  ==0 & dist_cat >2  &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != .
tab `var'  if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & grandparent_birth  ==1  & dist_cat <=2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != .
	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . & nograndparent_birth == 1
 }

 foreach var of varlist eventpost* event0 eventpre*{
 	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . & above75CC==1

    	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . & above75CC==0
		 	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . & above75CC==1& numper == 1

    	tab `var' if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat >2 &inc_f_adj != . & age_f != . & year!= . & resp_statecounty != . & above75CC==0 & numper == 1
 }
 
 
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==1 & numper == 1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & numper == 1
tab postperiod if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & dist_birth > 25 & numper == 1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & numper == 1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & dist_birth > 25 & numper == 1

foreach num of numlist 1 2 3 4{
	tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & dist_cat ==`num' & numper == 1
}
 
 
 
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0
tab postperiod if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & grandparent_birth ==0 & dist_birth > 25
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & nograndparent_birth ==1 & dist_birth > 25

foreach num of numlist 1 2 3 4{
	tab postperiod if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & dist_cat ==`num'
}
 
 
 
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & above75CC==1 & numper == 1
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & above75CC==0 & numper == 1
tab postperiod if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & CC_in10s!= . & numper == 1
 
 
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & above75CC==1 
tab postperiod if   insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & above75CC==0 
tab postperiod if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1) & CC_in10s!= . 

*/
 **** Event Studies
 eststo clear
 *** FIGURE 2
  preserve
*** Regression for Far away
 eststo: reghdfe  inc_adj sex_ind##(eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*)  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat > 2, absorb(age_f year  resp_statecounty ) vce(cluster uniqid)
 *** generating components for graphing
 predict var_p1  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & dist_cat > 2 , xb
 mat list e(b)
 qui matrix list e(V)
  ** Beta for non-grandparent location
   gen b1 = .
   gen bL1 = .
   gen bH1 = .
   g V1 = .
   replace b1 = 0 if eventpre2 == 1
   replace bL1 = 0 if eventpre2 == 1
   replace bH1 = 0 if eventpre2 == 1
   replace V1 = 0 if eventpre2 == 1
   
   replace b1 = _b[2.sex_ind#1.event0] if event0 == 1
   replace bL1 = _b[2.sex_ind#1.event0] - 1.96*_se[2.sex_ind#1.event0] if event0 == 1
   replace bH1 = _b[2.sex_ind#1.event0] + 1.96*_se[2.sex_ind#1.event0] if event0 == 1 
   replace V1 = _se[2.sex_ind#1.event0]^2 if event0 == 1
   foreach i of numlist 1 3 4 5{
   	   replace b1 = _b[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bL1 = _b[2.sex_ind#1.eventpre`i'] - 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bH1 = _b[2.sex_ind#1.eventpre`i'] + 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1 
   replace V1 = _se[2.sex_ind#1.eventpre`i']^2 if eventpre`i' == 1
   }
     foreach i of numlist 1(1)10{
   	   replace b1 = _b[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bL1 = _b[2.sex_ind#1.eventpost`i'] - 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bH1 = _b[2.sex_ind#1.eventpost`i'] + 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1 
   replace V1 = _se[2.sex_ind#1.eventpost`i']^2 if eventpost`i' == 1
   }
   

*** Regression for nearby   
 eststo: reghdfe inc_adj sex_ind##(eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*)  college hsdegree white black miss* [pw=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & dist_cat <= 2, absorb(age_f year  resp_statecounty ) vce(cluster uniqid)
 predict var_p2 if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & dist_cat <= 2, xb
   ** Beta for grandparent location
   
   gen b2 = .
   gen bL2 = .
   gen bH2 = .
   g V2 = .
   replace b2 = 0 if eventpre2 == 1
   replace bL2 = 0 if eventpre2 == 1
   replace bH2 = 0 if eventpre2 == 1
   replace V2 = 0 if eventpre2 == 1
   
   replace b2 = _b[2.sex_ind#1.event0] if event0 == 1
   replace bL2 = _b[2.sex_ind#1.event0] - 1.96*_se[2.sex_ind#1.event0] if event0 == 1
   replace bH2 = _b[2.sex_ind#1.event0] + 1.96*_se[2.sex_ind#1.event0] if event0 == 1 
   replace V2 = _se[2.sex_ind#1.event0]^2 if event0 == 1
   foreach i of numlist 1 3 4 5{
   	   replace b2 = _b[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bL2 = _b[2.sex_ind#1.eventpre`i'] - 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bH2 = _b[2.sex_ind#1.eventpre`i'] + 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1 
   replace V2 = _se[2.sex_ind#1.eventpre`i']^2 if eventpre`i' == 1
   }
     foreach i of numlist 1(1)10{
   	   replace b2 = _b[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bL2 = _b[2.sex_ind#1.eventpost`i'] - 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bH2 = _b[2.sex_ind#1.eventpost`i'] + 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1 
   replace V2 = _se[2.sex_ind#1.eventpost`i']^2 if eventpost`i' == 1
   }
   keep if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=50 & numper== 1 & (mother_miss != 1 |father_miss != 1)
   
 g eventtime = year - year_firstchild
 
 duplicates drop
 keep eventtime var_* b* bH* bL* V* grandparent_birth nograndparent_birth uniqid inc_adj dist_cat grandparent_weight
 sort eventtime
 drop if uniqid == 0
 duplicates tag uniqid eventtime, g(dup)
 keep if dup == 0
   summ  inc_adj if eventtime == -2 & dist_cat >2
 g denom1= r(mean) 
   summ  inc_adj if eventtime == -2 & dist_cat <=2
 g denom2 = r(mean) 
 
 drop inc_adj
 reshape long var_p b bL bH V denom, i(uniqid eventtime) j(modelver)
 
 drop dup
 gen var_c = var_p- b
 gen var_cL= var_p - bL
 gen var_cH= var_p -bH
 gen gap =b/denom
 gen boundL=bL/denom
 gen boundH =bH/denom
 
 collapse V b bH bL var_c var_p gap boundL boundH grandparent_birth nograndparent_birth , by(eventtime modelver)
 
 reshape wide V b bH bL var_c var_p gap boundL boundH , i(eventtime) j(modelver)
 
 g grandparent_diff = gap2 -gap1
 g DeltaSE_A = sqrt(V2/(var_c2^2) +V1/(var_c1^2))
 g grandparent_lb10 = grandparent_diff -1.68*DeltaSE_A
 g grandparent_ub10 = grandparent_diff +1.68*DeltaSE_A
  g grandparent_lb5 = grandparent_diff -1.96*DeltaSE_A
 g grandparent_ub5 = grandparent_diff +1.96*DeltaSE_A
 *** Panel B
 twoway (rarea grandparent_lb10 grandparent_ub10 eventtime, color(gs14%50) lcolor(gs12) lwidth(vvthin)) ///
 (connected grandparent_diff eventtime, lcolor(black) mcolor(black)) if eventtime >= -3 & eventtime <=7, yline(0, lcolor(red)) ///
 graphregion(color(white)) xtitle("Event Time (Years)") ytitle("Gap in Earnings Decline") ///
 legend(order(2 "Gap in Child Penalty (Near-Far)") col(1) ring(0) position(5)) xlabel(-3(1)7, nogrid) xline(-.5) name(gap_malecontrol1, replace)
 graph export "U:\output\gap_malecontrol02212024.png", replace
 *** Panel A
   twoway (rarea boundL1 boundH1 eventtime, color(gs14%50) lcolor(gs12) lwidth(vvthin)) (connected gap1 eventtime, lcolor(gs8) mcolor(gs8) msymbol(diamond)) ///
  (rarea boundL2 boundH2 eventtime, color(gs12%50) lcolor(gs12) lwidth(vvthin)) (connected gap2 eventtime, lcolor(black) mcolor(black)) if eventtime >= -3 & eventtime <=7, ///
  graphregion(color(white)) xtitle("Event Time (Years)") ytitle("% Change in Earnings Relative to Event Time -2") ///
  legend(order(2 "> 25 miles" 4 "< 25 miles") col(1) ring(0) position(1)) ///
   xlabel(-3(1)7, nogrid) xline(-.5)  name(splitlines_malecontrol1, replace)
 graph export "U:\output\penalty_malecontrol02212024.png", replace
 restore
 
 **** FIGURE A.II Child Penalty by Child Care Costs
  *** Child care , interacted with gender 
  preserve
  ** High Cost
 eststo: reghdfe  inc_adj sex_ind##(eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*) college hsdegree white black miss*  [pw=cc_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & above75CC== 1, absorb(age_f year  resp_statecounty ) vce(cluster uniqid)
 
 predict var_p1  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & (mother_miss != 1 |father_miss != 1) & above75CC== 1, xb
 mat list e(b)
 qui matrix list e(V)
  ** Beta for high cost location
   gen b1 = .
   gen bL1 = .
   gen bH1 = .
   g V1 = .
   replace b1 = 0 if eventpre2 == 1
   replace bL1 = 0 if eventpre2 == 1
   replace bH1 = 0 if eventpre2 == 1
   replace V1 = 0 if eventpre2 == 1
   
   replace b1 = _b[2.sex_ind#1.event0] if event0 == 1
   replace bL1 = _b[2.sex_ind#1.event0] - 1.96*_se[2.sex_ind#1.event0] if event0 == 1
   replace bH1 = _b[2.sex_ind#1.event0] + 1.96*_se[2.sex_ind#1.event0] if event0 == 1 
   replace V1 = _se[2.sex_ind#1.event0]^2 if event0 == 1
   foreach i of numlist 1 3 4 5{
   	   replace b1 = _b[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bL1 = _b[2.sex_ind#1.eventpre`i'] - 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bH1 = _b[2.sex_ind#1.eventpre`i'] + 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1 
   replace V1 = _se[2.sex_ind#1.eventpre`i']^2 if eventpre`i' == 1
   }
     foreach i of numlist 1(1)10{
   	   replace b1 = _b[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bL1 = _b[2.sex_ind#1.eventpost`i'] - 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bH1 = _b[2.sex_ind#1.eventpost`i'] + 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1 
   replace V1 = _se[2.sex_ind#1.eventpost`i']^2 if eventpost`i' == 1
   }
   

   *** Lower Cost Counties
 eststo: reghdfe inc_adj sex_ind##(eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*) college hsdegree white black miss*   [pw=cc_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & above75CC== 0, absorb(age_f year  resp_statecounty ) vce(cluster uniqid)
 predict var_p2 if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & (mother_miss != 1 |father_miss != 1)  & above75CC== 0, xb
   ** Beta for low cost
   
   gen b2 = .
   gen bL2 = .
   gen bH2 = .
   g V2 = .
   replace b2 = 0 if eventpre2 == 1
   replace bL2 = 0 if eventpre2 == 1
   replace bH2 = 0 if eventpre2 == 1
   replace V2 = 0 if eventpre2 == 1
   
   replace b2 = _b[2.sex_ind#1.event0] if event0 == 1
   replace bL2 = _b[2.sex_ind#1.event0] - 1.96*_se[2.sex_ind#1.event0] if event0 == 1
   replace bH2 = _b[2.sex_ind#1.event0] + 1.96*_se[2.sex_ind#1.event0] if event0 == 1 
   replace V2 = _se[2.sex_ind#1.event0]^2 if event0 == 1
   foreach i of numlist 1 3 4 5{
   	   replace b2 = _b[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bL2 = _b[2.sex_ind#1.eventpre`i'] - 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1
   replace bH2 = _b[2.sex_ind#1.eventpre`i'] + 1.96*_se[2.sex_ind#1.eventpre`i'] if eventpre`i' == 1 
   replace V2 = _se[2.sex_ind#1.eventpre`i']^2 if eventpre`i' == 1
   }
     foreach i of numlist 1(1)10{
   	   replace b2 = _b[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bL2 = _b[2.sex_ind#1.eventpost`i'] - 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1
   replace bH2 = _b[2.sex_ind#1.eventpost`i'] + 1.96*_se[2.sex_ind#1.eventpost`i'] if eventpost`i' == 1 
   replace V2 = _se[2.sex_ind#1.eventpost`i']^2 if eventpost`i' == 1
   }
   keep if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper== 1 & (mother_miss != 1 |father_miss != 1)
   
 g eventtime = year - year_firstchild
 
 duplicates drop
 keep eventtime var_* b* bH* bL* V* grandparent_birth nograndparent_birth uniqid inc_adj above75CC cc_weight
 sort eventtime
 drop if uniqid == 0
 duplicates tag uniqid eventtime, g(dup)
 keep if dup == 0
   summ  inc_adj if eventtime == -2 &  above75CC== 1
 g denom1= r(mean) 
   summ  inc_adj if eventtime == -2 & above75CC== 0
 g denom2 = r(mean) 
 
 drop inc_adj
 reshape long var_p b bL bH V denom, i(uniqid eventtime) j(modelver)
 
 drop dup
 gen var_c = var_p- b
 gen var_cL= var_p - bL
 gen var_cH= var_p -bH
 gen gap =b/denom
 gen boundL=bL/denom
 gen boundH =bH/denom
 
 collapse V b bH bL var_c var_p gap boundL boundH grandparent_birth nograndparent_birth , by(eventtime modelver)
 
 reshape wide V b bH bL var_c var_p gap boundL boundH , i(eventtime) j(modelver)
 
 g grandparent_diff = gap2 -gap1
 g DeltaSE_A = sqrt(V2/(var_c2^2) +V1/(var_c1^2))
 g grandparent_lb10 = grandparent_diff -1.68*DeltaSE_A
 g grandparent_ub10 = grandparent_diff +1.68*DeltaSE_A
  g grandparent_lb5 = grandparent_diff -1.96*DeltaSE_A
 g grandparent_ub5 = grandparent_diff +1.96*DeltaSE_A
 twoway (rarea grandparent_lb10 grandparent_ub10 eventtime, color(gs14%50) lcolor(gs12) lwidth(vvthin)) ///
 (connected grandparent_diff eventtime, lcolor(black) mcolor(black)) if eventtime >= -3 & eventtime <=7, yline(0, lcolor(red)) ///
 graphregion(color(white)) xtitle("Event Time (Years)") ytitle("Gap in Earnings Decline") ///
 legend(order(2 "Gap in Child Penalty (Low Cost- High Costs)") col(1) ring(0) position(5)) xlabel(-3(1)7, nogrid) xline(-.5) name(gapCC_malecontrol, replace)
 graph export "U:\output\gap_malecontrol_CCC02212024.png", replace
 
   twoway (rarea boundL1 boundH1 eventtime, color(gs14%50) lcolor(gs12) lwidth(vvthin)) (connected gap1 eventtime, lcolor(gs8) mcolor(gs8) msymbol(diamond)) ///
  (rarea boundL2 boundH2 eventtime, color(gs12%50) lcolor(gs12) lwidth(vvthin)) (connected gap2 eventtime, lcolor(black) mcolor(black)) if eventtime >= -3 & eventtime <=7, ///
  graphregion(color(white)) xtitle("Event Time (Years)") ytitle("% Change in Earnings Relative to Event Time -2") ///
  legend(order(2 "Above 75th Percentile" 4 "Below 75th Percentile") col(1) ring(0) position(1)) ///
   xlabel(-3(1)7, nogrid) xline(-.5)  name(splitlinesCC_malecontrol, replace)
  graph export "U:\output\penalty_malecontrol_CCC02212024.png", replace
 restore
 
 

 
 
 ** Baseline Means for event study groups
 eststo clear
estpost  summ inc_f_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & dist_cat >2   
eststo col1
 estpost summ inc_f_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & dist_cat <=2 
 eststo col2
 estpost  summ inc_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & dist_cat >2   
 eststo col3
estpost  summ inc_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1  & dist_cat <=2 
 eststo col4
 estpost  summ inc_f_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & dist_cat >2    & nograndparent_birth==1
 eststo col5
 estpost summ inc_f_adj [w=grandparent_weight] if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & dist_cat <=2 
 eststo col6
 
 estpost  summ inc_f_adj [w=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & above75CC==1
 eststo col7
  
 estpost  summ inc_f_adj [w=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & above75CC==0
  eststo col8
  estpost   summ inc_adj [w=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & above75CC==1
  eststo col9
 estpost  summ inc_adj [w=cc_weight]  if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & headspouse == 1 & above75CC==0
  
 eststo col10
 
 esttab col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 using "U:\output\eventstudy_baselinemean_02212024.csv", main(mean) replace


 
************************ EFFECTS ON EMPLOYMENT **********************************
use "U:\dtafiles\penaltysample_hoursoutcomes.dta", clear 
 
 **** Figure A.I Panel A
 eststo: reghdfe FTemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*   college hsdegree white black miss*   if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & dist_cat >2 , absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Far
   
   
 eststo: reghdfe FTemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*  college hsdegree white black miss* [pw=grandparent_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & numper ==1 & (mother_miss != 1 |father_miss != 1)   & dist_cat <=2, absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Near
 foreach num of numlist 1/5{
 	label var eventpre`num' "t-`num'"
	label var eventpost`num' "t+`num'"
 }
 foreach num of numlist 6/10{
 	label var eventpost`num' "t+`num'"
 }
 label var event0 "t=0"
 coefplot (Far, keep(event*) lcolor(gs8 ) mcolor(gs8 ) msymbol(diamond ) ciopts( color(gs12))) (Near, keep(event*) ciopts(color(gs12)) lcolor(gs12 ) mcolor(gs12 ) msymbol(circle )), vertical graphregion(color(white)) xtitle("Event Time (Years)") ytitle("Change in FT Employment") label omit xline(5.5) yline(0) name("FTEmp", replace) 
 graph export "U:\output\FT_penalty.png", replace
 
  **** Figure A.I Panel B 
 eststo: reghdfe PTemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*   college hsdegree white black miss*   if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & dist_cat >2 , absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Far
   
   
 eststo: reghdfe PTemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*  college hsdegree white black miss* [pw=grandparent_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & numper ==1 & (mother_miss != 1 |father_miss != 1)   & dist_cat <=2, absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Near
 foreach num of numlist 1/5{
 	label var eventpre`num' "t-`num'"
	label var eventpost`num' "t+`num'"
 }
 foreach num of numlist 6/10{
 	label var eventpost`num' "t+`num'"
 }
 label var event0 "t=0"
 coefplot (Far, keep(event*) lcolor(gs8 ) mcolor(gs8 ) msymbol(diamond ) ciopts( color(gs12))) (Near, keep(event*) ciopts(color(gs12)) lcolor(gs12 ) mcolor(gs12 ) msymbol(circle )), vertical graphregion(color(white)) xtitle("Event Time (Years)") ytitle("Change in PT Employment") label omit xline(5.5) yline(0) name("PTEmp", replace)
  graph export "U:\output\PT_penalty.png", replace
  **** Figure A.I Panel C
  eststo: reghdfe noemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*   college hsdegree white black miss*   if  insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40 & numper ==1 & (mother_miss != 1 |father_miss != 1)  & dist_cat >2 , absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Far
   
   
 eststo: reghdfe noemp_f eventpre5 eventpre4 eventpre3 eventpre2 eventpre1 event0 ///
 eventpost*  college hsdegree white black miss* [pw=grandparent_weight]   if insample2 == 1 & age_firstchild >= 20 & age_firstchild <=40  & numper ==1 & (mother_miss != 1 |father_miss != 1)   & dist_cat <=2, absorb(age_f year resp_statecounty) vce(cluster uniqid)
 estimates store Near
 foreach num of numlist 1/5{
 	label var eventpre`num' "t-`num'"
	label var eventpost`num' "t+`num'"
 }
 foreach num of numlist 6/10{
 	label var eventpost`num' "t+`num'"
 }
 label var event0 "t=0"
 coefplot (Far, keep(event*) lcolor(gs8 ) mcolor(gs8 ) msymbol(diamond ) ciopts( color(gs12))) (Near, keep(event*) ciopts(color(gs12)) lcolor(gs12 ) mcolor(gs12 ) msymbol(circle )),vertical graphregion(color(white)) xtitle("Event Time (Years)") ytitle("Change in Non-Employment") label omit xline(5.5) yline(0) name("NoEmp", replace)
  graph export "U:\output\NoEmp_penalty.png", replace
 
 
 ********************* MIGRATION DESCRIPTIVES ***********************************
 
 **** Note: The descriptives tables were not automated in code
 
 use "U:\dtafiles\descriptivessample_PSIDmigration.dta", clear
 *** TABLE 2 ******
rename totalmoveshome totalmovestohome



*** Column 1 of Table 2
summ totalmoves if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ totalmoves if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ totalmove_lifeperiod  if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ totalmove_lifeperiod if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1
summ totalmove_lifeperiod if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ totalmove_lifeperiod if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1  
summ totalmove_lifeperiod if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1  


*** Column 2 of Table 2
g nonmover= totalmoves== 0
g nonmover_lifeperiod = totalmove_lifeperiod == 0
summ nonmover if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ nonmover if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ nonmover_lifeperiod  if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ nonmover_lifeperiod if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1
summ nonmover_lifeperiod if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ nonmover_lifeperiod if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1  
summ nonmover_lifeperiod if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1  

*** Column 3 of Table 2
g oncemover = totalmoves == 1
g oncemover_lifeperiod = totalmove_lifeperiod == 1
summ oncemover if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ oncemover if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ oncemover_lifeperiod  if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ oncemover_lifeperiod if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1
summ oncemover_lifeperiod if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ oncemover_lifeperiod if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1  
summ oncemover_lifeperiod if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1 

*** Column 4 of Table 2
g multimover = totalmoves > 1
g multimover_lifeperiod = totalmove_lifeperiod > 1
summ multimover if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ multimover if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ multimover_lifeperiod  if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ multimover_lifeperiod if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1
summ multimover_lifeperiod if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ multimover_lifeperiod if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1  
summ multimover_lifeperiod if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1 

*** Column 5 of Table 2
g movehome_ever = totalmovestohome >0
g movehome_ever_lifeperiod = totalmovetohome_lifeperiod > 0
summ movehome_ever if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ movehome_ever if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ movehome_ever_lifeperiod  if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ movehome_ever_lifeperiod if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1
summ movehome_ever_lifeperiod if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ movehome_ever_lifeperiod if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1  
summ movehome_ever_lifeperiod if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1  

*** Column 6 of Table 2
summ  propor_hom if nochild == 1 & startage <=25 & endage>=50 & earliestage 
summ  propor_hom if nochild == 0 & startage <=25 & endage>=50 & earliestage 
summ  propor_home_period if childstatus == 1 & startage <=25 & endage>=50 & numofyears == 1 
summ propor_home_period if childstatus == 2 & startage <=25 & endage>=50 & numofyears == 1 
summ  propor_home_period if childstatus == 3 & startage <=25 & endage>=50 & numofyears == 1 
summ propor_home_period if childstatus == 4 & startage <=25 & endage>=50 & numofyears == 1 
summ propor_home_period if childstatus == 5 & startage <=25 & endage>=50 & numofyears == 1 



**** TABLE A.IV

g move_tohome_cond = .
replace move_tohome_cond = 0 if move_state == 1 & move_tohome == 0
replace move_tohome_cond = 1 if move_state == 1 & move_tohome == 1

** Row 1 and 4
ttest changeinc_f if nochild == 1 , by(move_state) // Mover vs. Stayer , Never Have Kids
ttest changeinc_f if nochild == 0 , by(move_state) // Mover vs. Stayer, Ever Have Kids
ttest changeinc_f if nochild == 0 & childstatus == 2, by(move_state) // Mover vs. Stayer, Young Kids

** Row 2 and 3
ttest changeinc_f if nochild == 1 , by(move_tohome_cond) // Move to Home vs. Move to non-home, Never Have Kids
ttest changeinc_f if nochild == 0 , by(move_tohome_cond) // Move to Home  vs. Move to non-home, Ever Have Kids
ttest changeinc_f if nochild == 0 & childstatus == 2, by(move_tohome_cond) // Move to Home  vs. Move to non-home, Young Kids
** Row 5 and 6
ttest changeinc_f if nochild == 1 & move_state == 0, by(same_state_parent) // Stayer in non-home vs. Stayer in home, never kids
ttest changeinc_f if nochild == 0 & move_state == 0, by(same_state_parent) // Stayer in non-home vs. Stayer in home, ever kids
ttest changeinc_f if nochild == 0 & childstatus == 2& move_state == 0, by(same_state_parent) // Stayer in non-home vs. Stayer in home, young kids

